{-- 
    As outlined in 'https://github.com/Frege/frege/issues/357 #357',
    the compiler decides that 'myFoldM' should be strict, despite the tail call
    'Maybe.>>=' returns lazy. This is unfortunate, because the recursion happens
    on the stack, instead through a Thunk returned by >>=
-}
module tests.comp.Issue357 where

myFoldM :: (b -> a -> Maybe b) -> b -> [a] -> Maybe b
myFoldM f z (x:xs) = f z x >>= \acc -> myFoldM f acc xs
myFoldM _ z []     = pure z

main = println $ myFoldM (\r _ -> Just $! succ r) 0 [1..5000]
